<template>
  <el-dialog v-model="visible" :close-on-click-modal="false" draggable :loading="loading">
    <div class="divide-title">客户信息</div>
    <el-descriptions class="app-container" :column="2">
      <el-descriptions-item label="账号：" :span="2">{{ data?.userName }}</el-descriptions-item>
      <el-descriptions-item label="名称：">{{ data?.nickName }}</el-descriptions-item>
      <el-descriptions-item label="状态：">
        <dict-tag style="display: inline-block" :options="sys_user_stat" :value="data.status" />
      </el-descriptions-item>
      <el-descriptions-item label="邮箱：">{{ data?.email || '无' }}</el-descriptions-item>
      <el-descriptions-item label="创建人：">{{ data?.createBy }}</el-descriptions-item>
      <el-descriptions-item label="联系方式：">{{ data?.phonenumber }}</el-descriptions-item>
      <el-descriptions-item label="创建时间：">{{ data?.createTime }}</el-descriptions-item>
    </el-descriptions>

    <div class="divide-title">公司信息</div>
    <el-descriptions class="app-container" :column="1">
      <el-descriptions-item label="公司名称：">{{ company?.name || '' }}</el-descriptions-item>
      <el-descriptions-item label="公司地址：">{{ company?.address || '' }}</el-descriptions-item>
      <el-descriptions-item label="联系方式：">{{ company?.mobile || '' }}</el-descriptions-item>
      <el-descriptions-item label="营业期限：">
        {{
          `${company?.bizLicenceBeginTime || ''}~ ${
            company?.longTerm == 1 ? '长期' : company?.bizLicenceEndTime || ''
          }`
        }}
      </el-descriptions-item>
      <el-descriptions-item label="营业执照：">
        <el-image
          style="width: 300px; height: 200px"
          :zoom-rate="1.2"
          :max-scale="7"
          :min-scale="0.2"
          :src="company?.bizLicence"
          :preview-src-list="[company?.bizLicence]"
          fit="contain"
        />
      </el-descriptions-item>
    </el-descriptions>
    <template #footer>
      <el-button @click="handleAction">关闭</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { getCompanyInfo } from '@/api/organization/company'

const { proxy } = getCurrentInstance()
const { sys_user_stat } = proxy.useDict('sys_user_stat')
const visible = ref(false)
const loading = ref(false)
const data = ref({})
const company = ref({})

async function init(obj = {}) {
  visible.value = true
  const { companyId } = data.value
  if (companyId && companyId == obj?.companyId) return

  data.value = obj
  try {
    const r = await getCompanyInfo(obj.companyId)
    company.value = r?.data?.companys
  } finally {
    loading.value = false
  }
}

function handleAction() {
  visible.value = false
}

defineExpose({ init })
</script>

<style lang="scss" scoped></style>
